/**
 * 
 */
package com.htht.smartschool.action.roles;

import java.util.List;

import com.htht.smartschool.action.baseaction.BaseAction;
import com.htht.smartschool.common.model.ParamData;
import com.htht.smartschool.common.servlet.DataContainer;
import com.htht.smartschool.model.roles.AdminRole;
import com.htht.smartschool.model.roles.IntoschoolRoles;
import com.htht.smartschool.model.roles.Role;
import com.htht.smartschool.model.roles.RoleStudent;
import com.htht.smartschool.model.user.TUser;
import com.htht.smartschool.service.roles.RolesService;
import com.htht.smartschool.util.system.GsonUtils;

/**
 * @author wuqiwei
 *
 */
public class RolesAction extends BaseAction {

	
	@Override
	public boolean processData(DataContainer obj, ParamData pd) {
		boolean flag = false;
		RolesService  rolesservice = new  RolesService();
		IntoschoolRoles intoschoolRoles = (IntoschoolRoles) GsonUtils.getInstance().fromJson(pd.getData(), IntoschoolRoles.class);
		AdminRole adminRole = (AdminRole) GsonUtils.getInstance().fromJson(pd.getData(), AdminRole.class);
		RoleStudent roleStudent = (RoleStudent) GsonUtils.getInstance().fromJson(pd.getData(), RoleStudent.class);
		Role  role = (Role) GsonUtils.getInstance().fromJson(pd.getData(), Role.class);
		if(pd.getCmd().equalsIgnoreCase("getintoschoolRoles")){
			List<IntoschoolRoles> list = rolesservice.getIntoSchoolRole(intoschoolRoles);//查询学生进出校信息
			if(list.size() > 0){
				flag = true;
				obj.setData(list);
			}else{
				obj.setData("查询进出校信息失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("deleteIntoschoolRoles")){
			boolean result = rolesservice.deleteIntoschoolRole(intoschoolRoles);//删除信息
			if(result){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("删除失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("updateIntoschoolRoles")){
			boolean result = rolesservice.updateIntoschoolRole(intoschoolRoles);//修改信息
			if(result){
				flag = true;
				obj.setData(result);
			}else {
				obj.setData("修改失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("insertIntoschoolRoles")){
			boolean result = rolesservice.insertIntoschoolRole(intoschoolRoles);//插入数据
			if(result){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("插入数据失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("queryAdminRole")){
			List<AdminRole> list = rolesservice.queryAdminRole(adminRole);//查询规则
			if(list.size() > 0){
				flag = true;
				obj.setData(list);
			}else{
				obj.setData("查询规则失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("deleteAdminRole")){
			boolean result =  rolesservice.deleteAdminRole(adminRole);//删除数据规则
			if(result){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("删除失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("updateAdminRole")){
			boolean result = rolesservice.updateAdminRole(adminRole);//修改数据规则
			if(result){
				flag = true;
				obj.setData(result);
			}else {
				obj.setData("修改失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("insertAdminRole")){
			boolean result = rolesservice.insertAdminRole(adminRole);//插入数据规则
			if(result){
				flag = true;
				obj.setData(result);
			}else {
				obj.setData("修改失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("batchaddRole")){
			boolean result = rolesservice.barchAddRole(roleStudent);//批量添加考勤
			if(result ){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("添加失败！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("queryRoleStudent")){
			List<RoleStudent> list = rolesservice.queryRoleStudent(roleStudent);
			if(list.size()>0){
				flag = true;
				obj.setData(list);
			}else {
				obj.setData("查询失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("queryRoleStudentByClass")){
			List<RoleStudent> list = rolesservice.queryRoleStudentByClass(roleStudent);
			if(list.size()>=0){
				flag = true;
				obj.setData(list);
			}else {
				obj.setData("查询失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("updateRoleStudent")){
			boolean result = rolesservice.updateRoleStudent(roleStudent);
			if(result){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("修改失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("deleteRoleStudent")){
			boolean result = rolesservice.deleteRoleStudnet(roleStudent);
			if(result){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("无法删除");
			}
		}else if(pd.getCmd().equalsIgnoreCase("insertRoleStudent")){
			boolean result = rolesservice.insertRoleStudent(roleStudent);
			if(result){
				flag = true;
				obj.setData(result);
			}else {
				obj.setData("插入失败");
			}
		}
		return flag;
	}

}
